<template>
  <!--出低价-->
  <el-dialog
    :close-on-click-modal="false"
    title="暂无报价"
    :visible.sync="dialogVisible4"
    :beforeClose="handleClose4"
    width="400px"
  >
    <div>
      <el-form
        size="mini"
        :model="sendForm4"
        label-width="100px"
        ref="sendForm4"
        :rules="rules4"
      >
        <el-form-item label="原因：" prop="unOrderReason">
          <el-select style="width: 200px" v-model="sendForm4.unOrderReason">
            <el-option
              v-for="item in reasonList"
              :label="item.reasonValue"
              :value="item.reasonValue"
              :key="item.reasonId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注：">
          <el-input
            type="textarea"
            style="width: 200px"
            v-model="sendForm4.unOrderRemark"
          ></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose4">取 消</el-button>
      <el-button type="primary" @click="handleConfirm4" :loading="btnLoading4"
        >确 认</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import {
  getAreaList,
  unOrderReasonList,
  inquiryOperate,
} from "@/api/allInLine/inquiry";
import { mapGetters } from "vuex";
import { Message } from "element-ui";

const defaultSendForm4 = {
  unOrderReason: "",
  inquiryId: "",
  unOrderRemark: "",
  unOrderType: "采购",
  operateType: "noQuotation",
};

export default {
  name: "index",
  data() {
    const isvalidateInput = (rule, value, callback) => {
      if (value > this.sendForm4.purchasePrice1) {
        callback(new Error("低价金额不能高于报价"));
      } else {
        callback();
      }
    };
    return {
      dialogVisible4: false,
      btnLoading4: false,
      sendForm4: JSON.parse(JSON.stringify(defaultSendForm4)),
      rules4: {
        unOrderReason: [
          { required: true, message: "请选择未成交原因", trigger: "change" },
        ],
      },
      data: [],
      reasonList: [],
      dataLoading: false,
    };
  },
  computed: {
    ...mapGetters(["name", "mobile", "userId"]),
  },
  components: {},
  created() {},
  filters: {},
  methods: {
    //显示我有低价
    showPop4(item) {
      this.dialogVisible4 = true;
      this.getUnOrderReasonList();
      this.sendForm4 = JSON.parse(JSON.stringify(defaultSendForm4));
      this.sendForm4.inquiryId = item.inquiryId;
    },
    //关闭我有低价
    handleClose4() {
      this.dialogVisible4 = false;
    },

    getUnOrderReasonList() {
      unOrderReasonList({ reasonType: "采购" }).then((res) => {
        this.reasonList = res;
      });
    },

    //确认提交
    handleConfirm4() {
      this.$refs.sendForm4.validate((valid) => {
        if (valid) {
          this.btnLoading4 = true;
          const data = JSON.parse(JSON.stringify(this.sendForm4));
          inquiryOperate(data)
            .then((res) => {
              Message.success("提交成功");
              this.btnLoading4 = false;
              this.$emit("update");
              this.dialogVisible4 = false;
            })
            .catch((err) => {
              this.btnLoading4 = false;
            });
        }
      });
    },
    //获取地区列表
    getAreaLists() {
      this.dataLoading = true;
      getAreaList().then((res) => {
        this.data = res;
        this.data2 = [];
        this.data2 = this.forTree(this.data);
        this.dataLoading = false;
      });
    },
    //去除不要的children
    forTree(list) {
      let newList = list;
      if (newList.length) {
        for (let i = 0; i < newList.length; i++) {
          if (newList[i].children && newList[i].children.length > 0) {
            this.forTree(newList[i].children);
          } else {
            delete newList[i].children;
          }
        }
        return newList;
      }
    },
  },
};
</script>

<style  lang="scss">
</style>
